package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.fragment.AllLotteryFragment;
import com.lottery.ruok.lottrey.retrofitModule.response.GetWholeCategoryResponse;

import java.util.ArrayList;

import ui.NoScrollGridView;

/**
 * Created by ASUS on 2017/11/13.
 */

public class AllLotteryListViewAdapter extends BaseAdapter {
    private ArrayList<GetWholeCategoryResponse> datas;
    private Context mContext;
    private AllLotteryFragment allLotteryFragment;
    public AllLotteryListViewAdapter(ArrayList<GetWholeCategoryResponse> getWholeCategoryResponses, Context context, AllLotteryFragment allLotteryFragment) {
        datas = getWholeCategoryResponses;
        mContext = context;
        this.allLotteryFragment = allLotteryFragment;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from
                    (mContext).inflate(R.layout.all_listview_item, null, false);
            holder.gridView = convertView.findViewById(R.id.grid_item);
            holder.name = convertView.findViewById(R.id.name);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.name.setText(datas.get(position).getName());
        if (holder.gridView != null) {
            AlllotteryGridAdapter gridViewAdapter = new AlllotteryGridAdapter(datas.get(position).getItems(), mContext, allLotteryFragment);
            holder.gridView.setAdapter(gridViewAdapter);
        }

        return convertView;

    }

    static class ViewHolder {
        NoScrollGridView gridView;
        TextView name;
    }
}
